
#ifndef PULSE_H_H
#define PULSE_H_H

#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

  typedef struct
  {
    uint8_t pulse_1s;
    uint8_t pulse_500ms;
    uint8_t pulse_250ms;
    uint8_t pulse_100ms;
    uint8_t pulse_125ms;
    uint8_t pulse_200ms;

    uint8_t pulse_50ms;
    uint8_t pulse_25ms;
    uint8_t pulse_20ms;
    uint8_t pulse_10ms;
    uint8_t pulse_5ms;

    uint8_t wave_1s;
    uint8_t wave_500ms;
    uint8_t wave_250ms;
    uint8_t wave_100ms;
    uint8_t wave_125ms;
    uint8_t wave_200ms;

    uint8_t wave_50ms;
    uint8_t wave_25ms;
    uint8_t wave_20ms;
    uint8_t wave_10ms;
    uint8_t wave_5ms;

    uint16_t xcnt_1s;
    uint16_t xcnt_500ms;
    uint16_t xcnt_250ms;
    uint16_t xcnt_100ms;
    uint16_t xcnt_125ms;
    uint16_t xcnt_200ms;

    uint16_t xcnt_50ms;
    uint16_t xcnt_25ms;
    uint16_t xcnt_20ms;
    uint16_t xcnt_10ms;
    uint16_t xcnt_5ms;

    uint16_t tick_old;
    uint32_t auto_cnt_100ms; // base in 100ms
    uint32_t auto_cnt_10ms;  // base in 10ms
    uint32_t auto_cnt_1s;    // base in 1s
  } timer_pulse_type;

  void pulse_init(timer_pulse_type *pulse, uint16_t tick_now);
  void pulse_creat(timer_pulse_type *pulse, uint16_t uTick_1ms);
  void mpulse_creat(timer_pulse_type *pulse, uint16_t uTick_1_25ms);
  void pulse5_creat(timer_pulse_type *pulse, uint16_t uTick_5ms);

  typedef struct
  {
    uint8_t pulse_100ms : 1;
    uint8_t pulse_200ms : 1;
    uint8_t pulse_500ms : 1;
    uint8_t pulse_1s : 1;

    uint8_t pulse_5ms : 1;
    uint8_t pulse_10ms : 1;
    uint8_t pulse_20ms : 1;
    uint8_t pulse_25ms : 1;
    uint8_t pulse_50ms : 1;

    uint8_t pulse_125ms : 1;
    uint8_t pulse_250ms : 1;

    uint8_t wave_100ms : 1; // pulse sync
    uint8_t wave_200ms : 1;
    uint8_t wave_500ms : 1;
    uint8_t wave_1s : 1;

    uint8_t wave_5ms : 1;
    uint8_t wave_10ms : 1;
    uint8_t wave_20ms : 1;
    uint8_t wave_25ms : 1;
    uint8_t wave_50ms : 1;

    uint8_t wave_125ms : 1;
    uint8_t wave_250ms : 1;

    uint8_t tick_old;
    uint8_t xcnt_100ms; // base on tick
    uint8_t xcnt_200ms; // base on 100ms
    uint8_t xcnt_500ms; // base on 100ms
    uint8_t xcnt_1s;    // base on 100ms
    uint8_t xcnt_5ms;   // base on tick
    uint8_t xcnt_10ms;  // base on tick
    uint8_t xcnt_20ms;  // base on tick
    uint8_t xcnt_25ms;  // base on tick
    uint8_t xcnt_50ms;  // base on tick
    uint8_t xcnt_125ms; // base on tick
    uint8_t xcnt_250ms; // base on 125ms

    uint32_t auto_cnt_100ms; // base on 100ms
    uint32_t auto_cnt_10ms;  // base on 10ms
    uint32_t auto_cnt_1s;    // base on 1s
  } sc_pulse_type;

  extern sc_pulse_type sc_pulse;

  void sc_pulse_creat(uint8_t uTick_1ms);
  void scm_pulse_creat(uint8_t uTick_1_25ms);
  void sc5_pulse_creat(uint8_t uTick_5ms);

#ifdef __cplusplus
}
#endif

#endif /* LEDCTR_H */
